#include <string.h>
#include <stdio.h>
#include <math.h>

int Hex2Char(unsigned int fromi, unsigned char* toc) {
    //char array[40] = { '1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
    ////char* tmp = array[fromi-1];
    ////puts((char *)tmp);
    //printf("%d",fromi);
    //for (fromi = 1; fromi <= 15; fromi++) {
    //    printf("%d->%c\n", fromi, array[fromi - 1]);
    //}
    return 0;
}

int Char2Hex(unsigned char fromc, unsigned int* toi) {
    /*char array[40] = { '1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
    int i,tmp;
    for ( i = 0; i < 16; i++)
    {
        if(!strcmp((const char *)array[i], (const char*)fromc)) {
            printf("%c->%d", array[i], i);
            tmp=i;
            toi = &tmp;
        }
    }*/
    return 0;
}

int Bitstr2ByteArr(unsigned char* bs, unsigned char* ba) {
    //printf("%s", bs);
    //int i;
    //int tmp,sum=0;
    //for ( i = 0; i < 5; i++)
    //{
    //    printf("%c\n", bs[i]);
    //    if (bs[i]=='1')
    //    {
    //        printf("%d\n", 2 ^ i);
    //        tmp = 1 * (2^i);
    //        sum += tmp;
    //        printf("%d\n", tmp);
    //    }
    //    printf("%d\n", sum);
    //}
    //
    return 0;
}
int ByteArr2Bitstr(unsigned char* ba, unsigned char* bs) {
    return 0;
}

int Int2ByteArr(unsigned int i, unsigned char* ba) {
    //pBuf = (unsigned char*)malloc(72 * 128 * sizeof(unsigned char));
    ba[0] = (unsigned char)(i & 0xff);
    ba[1] = (unsigned char)((i & 0xff00) >> 8);
    ba[2] = (unsigned char)((i & 0xff0000) >> 16);
    ba[3] = (unsigned char)((i & 0xff000000) >> 24);
    return 0;
}

int ByteArr2Int(unsigned char* ba, unsigned int* i) {
    unsigned int sum=0;
    int temp;
    for (int j = 3; j >= 0; j--)
    {
        printf("%d\n", ba[j]);
        temp = ba[j] * pow(16 ,(3 - j)*2);
        printf("->%d\n", temp);
        sum += temp;
        printf("->%d\n", sum);
    }
    
    i = &sum;
    return 0;
}